package cn.sunchis.demo.es.ctrl;

import java.util.Optional;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import cn.sunchis.demo.es.model.Book;
import cn.sunchis.demo.es.repository.BookRepository;

@RestController
public class BookController {
	@Resource
    private BookRepository bookRepository;
	
	@RequestMapping(value="/add/{id}/", method=RequestMethod.GET)
    public String add(@PathVariable("id")String id) {
    	Book book;
    	
//    	for (int i = 0; i < 10; i++) {
//			id += i;
//			
//			if (personDAO.exists(id)) {
//				continue;
//			}
//			
//			person = new Person();
//			person.setAge(random.nextInt());
//			person.setId(id);
//			person.setName(id + "-name");
//			person.setPhone(id + "-phone");
//			
//			personDAO.save(person);
//		}
    	
    	return "add success";
    }
	
	@RequestMapping(value="/get/", method=RequestMethod.GET)
	public Object getByName() {
		//Optional<Book> book = bookRepository.findById("1001");
		Book book = bookRepository.findOne("1001");
		return book;
	}
}
